/*
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

/*
 * @(#)StmtClient1.java	1.10 02/01/12
 */

package jdbcts.statement;

import java.io.*;
import java.util.*;
import java.math.*;

import java.sql.*;
import javax.sql.*;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import com.sun.cts.util.*;
import com.sun.cts.porting.*;
import com.sun.cts.harness.*;

import java.rmi.RemoteException;

import javasoft.sqe.javatest.Status;
import jdbcts.SuperTest;
import jdbcts.common.DataSourceConnection;
import jdbcts.common.DriverManagerConnection;
import jdbcts.common.dbSchema;

import com.sun.cts.tests.jdbc.ee.common.*;

// Merant DataSource class
//import com.merant.sequelink.jdbcx.datasource.*;

/**
 * The StmtClient1 class tests methods of Statement interface using Sun's J2EE
 * Reference Implementation.
 * 
 * @author
 * @version 1.7, 06/16/99
 */

public class StmtClient1 extends SuperTest implements Serializable
{
    private static final String testName = "jdbc.ee.stmt.stmt1";

    // Naming specific member variables
    private CTSNamingContextInterface jc = null;

    // Harness requirements

    private transient static Connection conn = null;

    private static ResultSet rs = null;

    private static Statement stmt = null;

    private DataSource ds1 = null;

    private static dbSchema dbSch = null;

    private static String drManager = null;

    private Properties sqlp = null;

    /* Run test in standalone mode */
    // public static void main(String[] args)
    // {
    // StmtClient1 theTests = new StmtClient1();
    // Status s=theTests.run(args, System.out, System.err);
    // s.exit();
    // }
    /* Test setup: */
    /*
     * @class.setup_props: Driver, the Driver name; db1, the database name with
     * url; user1, the database user name; password1, the database password;
     * db2, the database name with url; user2, the database user name;
     * password2, the database password; DriverManager, flag for DriverManager;
     * ptable, the primary table; ftable, the foreign table; cofSize, the
     * initial size of the ptable; cofTypeSize, the initial size of the ftable;
     * binarySize, size of binary data type; varbinarySize, size of varbinary
     * data type; longvarbinarySize, size of longvarbinary data type;
     * 
     * @class.testArgs: -ap ctssql.stmt
     */
    @BeforeClass
    // public void setup(String[] args, Properties p) throws Exception
    public static void setup() throws Exception
    {
	try
	{
	    try
	    {
		// drManager = p.getProperty("DriverManager","");
		drManager = isDRManager;
		 if (drManager.length() == 0)
		 throw new Exception("Invalid DriverManager Name");
		// sqlp=p;
		//
		 if(drManager.equals("yes"))
		 {
		logMsg("Using DriverManager");
		DriverManagerConnection dmCon = new DriverManagerConnection();
		// conn = dmCon.getConnection(n);
		conn = dmCon.getConnection(null);
		 }
		 else
		 {
		 logMsg("Using DataSource");
		 DataSourceConnection dsCon = new DataSourceConnection();
//		 conn = dsCon.getConnection(p);
		 conn = dsCon.getConnection(null);
		 }
		stmt = conn.createStatement();
		dbSch = new dbSchema();
		// dbSch.createData(p,conn);
	    }
	    catch (SQLException ex)
	    {
		logErr("SQL Exception : " + ex.getMessage());
	    }
	}
	catch (Exception e)
	{
	    logErr("Setup Failed!");
	    TestUtil.printStackTrace(e);
	}
    }

    /*
     * @testName: testClearWarnings
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The ClearWarnings clears the SQLWarnings associated with the statement
     * object. After a call to this method, a call to getWarnings will return a
     * null SQLWarning object. (See JDK 1.2.2 API Documentation)
     * 
     * @test_Strategy: Get a Statement object and call clearWarnings() method on
     * the statement object.Further calling the getWarnings() method should
     * return a null SQLWarning object
     */
    @Test
    public void testClearWarnings() throws Exception
    {
	try
	{

	    SQLWarning sWarning = stmt.getWarnings();
	    if (sWarning != null)
	    {
		logMsg("Calling clearWarnings method ");
		stmt.clearWarnings();
		sWarning = stmt.getWarnings();

		if (!(sWarning instanceof SQLWarning))
		{
		    logMsg("clearWarnings clears the SQLWarnings");
		}
		else
		{
		    logErr("clearWarnings does not clear the SQLWarning");
		    throw new Exception("Call to clearWarnings is Failed!");
		}
	    }
	    else
	    {
		logErr("getWarnings() returns a null SQLWarning object");
	    }

	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to clearWarnings is Failed!");
	}
	catch (Exception ex)
	{
	    logErr("Unexpected Exception" + ex.getMessage());
	    throw new Exception("Call to clearWarnings is Failed!");
	}
    }

    /*
     * @testName: testClose
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The close method closes the statement object.When a Statement object is
     * closed, its current ResultSet object, if one exists, is also closed. (See
     * JDK 1.2.2 API Documentation)
     * 
     * @test_Strategy: Get a Statement object and call close() method and call
     * executeQuery() method to check and it should throw SQLException
     */
    @Test
    public void testClose() throws Exception
    {
	Statement statemt = null;
	boolean sqlExceptFlag = false;
	try
	{
	    statemt = conn.createStatement();

	    // invoking the Close method
	    logMsg("Calling close method");
	    statemt.close();

	    // String sSelCoffee = sqlp.getProperty("SelCoffeeAll","");
	    String sSelCoffee = queryAll;
	    logMsg("Query String : " + sSelCoffee);

	    try
	    {
		rs = statemt.executeQuery(sSelCoffee);
	    }
	    catch (SQLException sql)
	    {
		sqlExceptFlag = true;
	    }
	    if (sqlExceptFlag)
	    {
		logMsg("close method closes the Statement object");
	    }
	    else
	    {
		logErr("close method does not close the Statement object");
		throw new Exception("Call to close method is Failed!");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to close is Failed!");
	}
	catch (Exception e)
	{
	    logErr("Unexpected Exception " + e.getMessage());
	    throw new Exception("Call to close is Failed!", e);
	}
    }

    /*
     * @testName: testExecute01
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The execute(String sql) method returns a boolean value; true if the first
     * result is ResultSet or false if it is an integer. (See JDK 1.2.2 API
     * Documentation)
     * 
     * @test_Strategy: Call execute(String sql) of updating a row It should
     * return a boolean value and the value should be equal to false
     */
    @Test
    public void testExecute01() throws Exception
    {
	boolean executeFlag = false;
	try
	{
	    // String sSqlStmt = sqlp.getProperty("Upd_Coffee_Tab","");
	    String sSqlStmt = setDocument;
	    logMsg("Sql Statement to be executed  " + sSqlStmt);

	    logMsg("Calling execute method ");
	    executeFlag = stmt.execute(sSqlStmt);

	    if (!executeFlag)
	    {
		logMsg("execute method executes the SQL Statement ");
	    }
	    else
	    {
		logErr("execute method does not execute the SQL Statement");
		throw new Exception("Call to execute is Failed!");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to execute is Failed!");
	}
	catch (Exception e)
	{
	    logErr("Unexpected Exception " + e.getMessage());
	    throw new Exception("Call to execute is Failed!", e);
	}
    }

    /*
     * @testName: testExecute02
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The execute(String sql) method returns a boolean value; true if the first
     * result is ResultSet or false if it is an integer. (See JDK 1.2.2 API
     * Documentation)
     * 
     * @test_Strategy: Get a Statement object and call execute(String sql) of
     * selecting rows from the database It should return a boolean value and the
     * value should be equal to true
     */
    @Test
    public void testExecute02() throws Exception
    {
	boolean executeFlag = false;
	try
	{
	    // String sSqlStmt = sqlp.getProperty("Sel_Coffee_Tab","");
	    String sSqlStmt = queryAll;
	    logMsg("Sql Statement to be executed  " + sSqlStmt);

	    logMsg("Calling execute method ");
	    executeFlag = stmt.execute(sSqlStmt);

	    if (executeFlag)
	    {
		logMsg("execute method executes the SQL Statement ");
	    }
	    else
	    {
		logErr("execute method does not execute the SQL Statement");
		throw new Exception("Call to execute is Failed!");
	    }

	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to execute is Failed!");
	}
	catch (Exception e)
	{
	    logErr("Unexpected Exception " + e.getMessage());
	    throw new Exception("Call to execute is Failed!", e);
	}
    }

    /*
     * @testName: testExecuteQuery01
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The executeQuery(String sql) method returns a ResultSet object; It may
     * return an empty ResultSet object but never returns null. This method
     * throws SQLException if an error occurs in processing SQL statement or if
     * the SQL statement generates a row count instead of ResultSet. (See
     * JDK1.2.2 API documentation)
     * 
     * @test_Strategy: Get a Statement object and call executeQuery(String sql)
     * to select a row from the database It should return a ResultSet object
     */
    @Test
    public void testExecuteQuery01() throws Exception
    {
	ResultSet reSet = null;
	try
	{
	    // String sSqlStmt = sqlp.getProperty("SelCoffeeAll","");
	    String sSqlStmt = queryAll;
	    logMsg("SQL Statement to be executed  :  " + sSqlStmt);

	    // invoking the executeQuery
	    logMsg("Calling executeQuery method ");
	    reSet = stmt.executeQuery(sSqlStmt);

	    if (reSet instanceof ResultSet)
	    {
		logMsg("executeQuery method returns a ResultSet object");
	    }
	    else
	    {
		logErr("executeQuery method does not return a ResultSet object");
		throw new Exception("Call to executeQuery is Failed!");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to executeQuery is Failed!");
	}
	catch (Exception e)
	{
	    logErr("Unexpected Exception " + e.getMessage());
	    throw new Exception("Call to executeQuery is Failed!", e);
	}
    }

    /*
     * @testName: testExecuteQuery02
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The executeQuery(String sql) method returns a ResultSet object; It may
     * return an empty ResultSet object but never returns null. This method
     * throws SQLException if an error occurs in processing SQL statement or if
     * the SQL statement generates a row count instead of ResultSet. (See
     * JDK1.2.2 API documentation)
     * 
     * @test_Strategy: Get a Statement object and call executeQuery(String sql)
     * to select a non-existent row from the database It should return a
     * ResultSet object which is empty and call ResultSet.next() method to check
     * and it should return a false
     */
    @Test
    public void testExecuteQuery02() throws Exception
    {
	ResultSet reSet = null;
	try
	{
	    // String sSqlStmt = sqlp.getProperty("SelCoffeeNull","");
	    String sSqlStmt = queryNull;
	    logMsg("SQL Statement to be executed  :  " + sSqlStmt);

	    // invoking the executeQuery
	    logMsg("Calling executeQuery method ");
	    reSet = stmt.executeQuery(sSqlStmt);

	    if (!reSet.next())
	    {
		logMsg("executeQuery method returns an Empty ResultSet for Non-Existent row");
	    }
	    else
	    {
		logErr("executeQuery method does not return an Empty ResultSet for non-existent row");
		throw new Exception("Call to executeQuery is Failed!");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to executeQuery is Failed!");
	}
	catch (Exception e)
	{
	    logErr("Unexpected Exception " + e.getMessage());
	    throw new Exception("Call to executeQuery is Failed!", e);
	}
    }

    /*
     * @testName: testExecuteQuery03
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The executeQuery(String sql) method returns a ResultSet object; It may
     * return an empty ResultSet object but never returns null. This method
     * throws SQLException if an error occurs in processing SQL statement or if
     * the SQL statement generates a row count instead of ResultSet. (See
     * JDK1.2.2 API documentation)
     * 
     * 
     * @test_Strategy: Get a Statement object and call executeQuery(String sql)
     * to insert a row from the database It should throw SQLException
     */
    @Test
    public void testExecuteQuery03() throws Exception
    {
	ResultSet reSet = null;
	boolean sqlExceptFlag = false;
	try
	{
	    // String sSqlStmt = sqlp.getProperty("Ins_Coffee_Tab","");
	    String sSqlStmt = setDocument;
	    logMsg("SQL Statement to be executed  :  " + sSqlStmt);

	    try
	    {
		// invoking the executeQuery with the Insert statement
		logMsg("Calling executeQuery method ");
		reSet = stmt.executeQuery(sSqlStmt);
	    }
	    catch (SQLException sql)
	    {
		sqlExceptFlag = true;
	    }
	    if (!sqlExceptFlag)
	    {
		logErr("executeQuery method executes an Insert Statement");
		throw new Exception("Call to executeQuery is Failed!");
	    }
	    else
	    {
		logMsg("executeQuery method does not execute an Insert Statement");
	    }
	}
	catch (Exception e)
	{
	    logErr("Unexpected Exception " + e.getMessage());
	    throw new Exception("Call to executeQuery is Failed!", e);
	}
    }

    /*
     * @testName: testExecuteUpdate01
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The executeUpdate(String sql) method returns a integer value; The value
     * indicates the number of rows affected by INSERT, DELETE or UPDATE
     * specified in the sql; 0 if no rows were affected or the statement
     * executed was a DDL statement. This method throws SQLException if an error
     * occurs in processing SQL statement or if the SQL statement generates a
     * ResultSet. (See JDK1.2.2 API documentation)
     * 
     * @test_Strategy: Get a Statement object and call executeUpdate(String sql)
     * It should return an int value which is equal to row count
     */
    @Test
    public void testExecuteUpdate01() throws Exception
    {
	int updCount = 0;
	int retRowCount = 0;
	try
	{
	    // String sSqlStmt = sqlp.getProperty("Upd_Coffee_Tab","");
	    String sSqlStmt = setDocument;
	    logMsg("Update String  : " + sSqlStmt);

	    // invoking the executeUpdate method
	    logMsg("Calling executeUpdate method ");
	    updCount = stmt.executeUpdate(sSqlStmt);

	    // to get the query which returns number of rows affected
	    // String countQuery = sqlp.getProperty("Coffee_Updcount_Query","");
	    // logMsg("Query String :  " + countQuery);
	    // rs=stmt.executeQuery(countQuery);
	    // rs.next();
	    // retRowCount = rs.getInt(1);
	    retRowCount = docID;
	    logMsg("Number of rows in the table with the specified condition  "
		    + retRowCount);

	    if (updCount == retRowCount)
	    {
		logMsg("executeUpdate executes the SQL Statement ");
	    }
	    else
	    {
		logErr("executeUpdate does not execute the SQL Statement ");
		throw new Exception("Call to executeUpdate is Failed!");
	    }

	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to executeUpdate is Failed!");
	}
	catch (Exception e)
	{
	    logErr("Unexpected Exception " + e.getMessage());
	    throw new Exception("Call to executeUpdate is Failed!", e);
	}
    }

    /*
     * @testName: testExecuteUpdate03
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The executeUpdate(String sql) method returns a integer value; The value
     * indicates the number of rows affected by INSERT, DELETE or UPDATE
     * specified in the sql; 0 if no rows were affected or the statement
     * executed was a DDL statement. This method throws SQLException if an error
     * occurs in processing SQL statement or if the SQL statement generates a
     * ResultSet. (See JDK1.2.2 API documentation)
     * 
     * @test_Strategy: Get a Statement object and call executeUpdate(String sql)
     * for selecting row from the table It should throw a SQL Exception
     */
    @Test
    public void testExecuteUpdate03() throws Exception
    {
	boolean sqlExceptFlag = false;
	int updCount = 0;
	try
	{
	    // String sSqlStmt = sqlp.getProperty("Sel_Coffee_Tab","");
	    String sSqlStmt = queryAll;
	    logMsg("SQL String of non - existent row  :  " + sSqlStmt);

	    try
	    {
		logMsg("Calling executeUpdate method ");
		updCount = stmt.executeUpdate(sSqlStmt);
	    }
	    catch (SQLException sqle)
	    {
		sqlExceptFlag = true;
	    }

	    if (sqlExceptFlag)
	    {
		logMsg("executeUpdate does not execute the SQL statement on non-existent row");
	    }
	    else
	    {
		logErr("executeUpdate executes the SQL statement on non-existent row");
		throw new Exception("Call to executeUpdate is Failed!");
	    }

	}
	catch (Exception e)
	{
	    logErr("Unexpected Exception " + e.getMessage());
	    throw new Exception("Call to executeUpdate is Failed!", e);
	}
    }

    /*
     * @testName: testGetFetchDirection
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The getFetchDirection() method returns a integer value; The value that is
     * been set by the setFetchDirection method. If no fetch direction has been
     * set, the return value is implementation specific. (See JDK1.2.2 API
     * documentation)
     * 
     * @test_Strategy: Get a Statement object and call the getFetchDirection()
     * method It should return a int value and the value should be equal to any
     * of the values FETCH_FORWARD or FETCH_REVERSE or FETCH_UNKNOWN
     */
    @Test
    public void testGetFetchDirection() throws Exception
    {
	int fetchDirVal = 0;
	try
	{
	    // invoke on the getFetchDirection
	    logMsg("Calling getFetchDirection method ");
	    fetchDirVal = stmt.getFetchDirection();

	    if (fetchDirVal == ResultSet.FETCH_FORWARD)
	    {
		logMsg("getFetchDirection method returns ResultSet.FETCH_FORWARD ");
	    }
	    else
		if (fetchDirVal == ResultSet.FETCH_REVERSE)
		{
		    logMsg("getFetchDirection method returns ResultSet.FETCH_REVERSE");
		}
		else
		    if (fetchDirVal == ResultSet.FETCH_UNKNOWN)
		    {
			logMsg("getFetchDirection method returns ResultSet.FETCH_UNKNOWN");
		    }
		    else
		    {
			logErr(" getFetchDirection method returns a invalid value");
			throw new Exception(
				"Call to getFetchDirection is Failed");
		    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getFetchDirection is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getFetchDirection is Failed!", e);
	}
    }

    /*
     * @testName: testGetFetchSize
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The getFetchSize() method returns a integer value; The value that is been
     * set by the setFetchSize method. If no fetch size has been set, the return
     * value is implementation specific. (See JDK1.2.2 API documentation)
     * 
     * @test_Strategy: Get a ResultSet object and call the getFetchSize() method
     * It should return a int value
     */
    @Test
    public void testGetFetchSize() throws Exception
    {
	try
	{
	    // invoke on the getFetchSize
	    logMsg("Calling getFetchSize on Statement");
	    int fetchSizeVal = stmt.getFetchSize();

	    if (fetchSizeVal >= 0)
	    {
		logMsg("getFetchSize method returns :" + fetchSizeVal);
	    }
	    else
	    {
		logErr(" getFetchSize method returns a invalid value");
		throw new Exception("Call to getFetchSize is Failed!");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getFetchSize is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getFetchSize is Failed!", e);
	}
    }

    /*
     * @testName: testGetMaxFieldSize
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The getMaxFieldSize() method returns a integer value; The value
     * representing the current maximum number of bytes that a ResultSet column
     * may contain. Zero means that there is no limit. (See JDK1.2.2 API
     * documentation)
     * 
     * @test_Strategy: Get a Statement object and call the getMaxFieldSize()
     * method It should return a int value
     */
    @Test
    public void testGetMaxFieldSize() throws Exception
    {
	try
	{
	    // invoke on the getMaxFieldSize
	    logMsg("Calling getMaxFieldSize on Statement");
	    int maxFieldSizeVal = stmt.getMaxFieldSize();

	    if (maxFieldSizeVal >= 0)
	    {
		logMsg("getMaxFieldSize method returns :" + maxFieldSizeVal);
	    }
	    else
	    {
		logErr(" getMaxFieldSize method returns a invalid value");
		throw new Exception("Call to getMaxFieldSize is Failed!");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getMaxFieldSize is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getMaxFieldSize is Failed!", e);
	}
    }

    /*
     * @testName: testGetMaxRows
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The getMaxRows() method returns a integer value; The value representing
     * the current maximum number of rows that a ResultSet object can contain.
     * Zero means that there is no limit. (See JDK1.2.2 API documentation)
     * 
     * @test_Strategy: Get a Statement object and call the getMaxRows() method
     * It should return a int value
     */
    @Test
    public void testGetMaxRows() throws Exception
    {
	try
	{
	    // invoke on the getFetchSize
	    logMsg("Calling getMaxRows on Statement");
	    int maxRowsVal = stmt.getMaxRows();

	    if (maxRowsVal >= 0)
	    {
		logMsg("getMaxRows method returns :" + maxRowsVal);
	    }
	    else
	    {
		logErr(" getMaxRows method returns a invalid value");
		throw new Exception("Call to getMaxRows is Failed!");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getMaxRows is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getMaxRows is Failed!", e);
	}
    }

    /*
     * @testName: testGetMoreResults01
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The getMoreResults() method returns a boolean value; true if the next
     * result is ResultSet object; false if it is an integer indicating that it
     * is an update count or there are no more results. There are no more
     * results when the following condition is satisfied. (getMoreResults==false
     * && getUpdatecount==-1) (See JDK1.2.2 API documentation)
     * 
     * @test_Strategy: Get a Statement object and call the execute() method for
     * selecting a row and call getMoreResults() method It should return a
     * boolean value
     */
    @Test
    public void testGetMoreResults01() throws Exception
    {
	try
	{
	    // String sSqlStmt = sqlp.getProperty("SelCoffeeAll","");
	    String sSqlStmt = queryAll;
	    logMsg("Query String : " + sSqlStmt);

	    stmt.execute(sSqlStmt);

	    // invoke on the getMoreResults
	    logMsg("Calling getMoreResults on Statement");
	    boolean moreResVal = stmt.getMoreResults();

	    if ((moreResVal == true) || (moreResVal == false))
	    {
		logMsg("getMoreResults method returns :" + moreResVal);
	    }
	    else
	    {
		logErr(" getMoreResults method returns a invalid value");
		throw new Exception("Call to getMoreResults is Failed!");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getMoreResults is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getMoreResults is Failed!", e);
	}
    }

    /*
     * @testName: testGetMoreResults02
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The getMoreResults() method returns a boolean value; true if the next
     * result is ResultSet object; false if it is an integer indicating that it
     * is an update count or there are no more results. There are no more
     * results when the following condition is satisfied. (getMoreResults==false
     * && getUpdatecount==-1) (See JDK1.2.2 API documentation)
     * 
     * @test_Strategy: Get a Statement object and call the execute() method for
     * selecting a non-existent row and call getMoreResults() method It should
     * return a boolean value and the value should be equal to false
     */
    @Test
    public void testGetMoreResults02() throws Exception
    {
	try
	{
	    // String sSqlStmt = sqlp.getProperty("SelCoffeeNull","");
	    String sSqlStmt = queryNull;
	    logMsg("Query String : " + sSqlStmt);

	    stmt.execute(sSqlStmt);

	    // invoke on the getMoreResults
	    logMsg("Calling getMoreResults on Statement");
	    boolean moreResVal = stmt.getMoreResults();

	    if (!moreResVal)
	    {
		logMsg("getMoreResults method returns :" + moreResVal);
	    }
	    else
	    {
		logErr(" getMoreResults method returns a invalid value");
		throw new Exception("Call to getMoreResults is Failed!");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getMoreResults is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getMoreResults is Failed!", e);
	}
    }

    /*
     * @testName: testGetMoreResults03
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The getMoreResults() method returns a boolean value; true if the next
     * result is ResultSet object; false if it is an integer indicating that it
     * is an update count or there are no more results. There are no more
     * results when the following condition is satisfied. (getMoreResults==false
     * && getUpdatecount==-1) (See JDK1.2.2 API documentation)
     * 
     * @test_Strategy: Get a Statement object and call the execute() method for
     * updating a row and call getMoreResults() method It should return a
     * boolean value and the value should be equal to false
     */
    @Test
    public void testGetMoreResults03() throws Exception
    {
	try
	{
	    // String sSqlStmt = sqlp.getProperty("Upd_Coffee_Tab","");
	    String sSqlStmt = setDocument;
	    logMsg("Query String : " + sSqlStmt);

	    stmt.execute(sSqlStmt);

	    // invoke on the getMoreResults
	    logMsg("Calling getMoreResults on Statement");
	    boolean moreResVal = stmt.getMoreResults();

	    if (!moreResVal)
	    {
		logMsg("getMoreResults method returns :" + moreResVal);
	    }
	    else
	    {
		logErr(" getMoreResults method returns a invalid value");
		throw new Exception("Call to getMoreResults is Failed!");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getMoreResults is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getMoreResults is Failed!", e);
	}
    }

    /*
     * @testName: testGetQueryTimeout
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The getQueryTimeout() method returns a integer value; The value indicates
     * the current query timeout limit in seconds. Zero means that there is no
     * time limit. (See JDK1.2.2 API documentation)
     * 
     * @test_Strategy: Get a Statement object and call getMoreResults() method
     * It should return a int value
     */
    @Test
    public void testGetQueryTimeout() throws Exception
    {
	int queryTimeout = 0;
	try
	{
	    // invoking getQueryTimeout method
	    logMsg("Calling getQueryTimeout on Statement");
	    queryTimeout = stmt.getQueryTimeout();

	    if (queryTimeout >= 0)
	    {
		logMsg("getQueryTimeout method returns :" + queryTimeout);
	    }
	    else
	    {
		logErr(" getQueryTimeout method returns a invalid value");
		throw new Exception("Call to getQueryTimeout is Failed!");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getQueryTimeout is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getQueryTimeout is Failed!", e);
	}
    }

    /*
     * @testName: testGetResultSet01
     * 
     * @assertion: The Statement object provides methods for executing SQL
     * statements and retrieving results.(See section 40.1 of JDBC 2.0 API
     * Reference & Tutorial second edition).
     * 
     * The driver must provide full support for Statement methods. The driver
     * must also support all the methods for executing SQL Statements in a
     * single batch (Batch Updates). (See section 6.2.2.3 of Java2 Platform
     * Enterprise Edition(J2EE) Specification v1.2)
     * 
     * The getResultSet() method returns a ResultSet object; the current result
     * set as a ResultSet object; null if the result is an integer indicating
     * that it is an update count or there are no more results.(See JDK1.2.2 API
     * documentation)
     * 
     * @test_Strategy: Get a Statement object and call execute() method for
     * selecting a row and call getResultSet() method It should return a
     * ResultSet object
     */
    @Test
    public void testGetResultSet01() throws Exception
    {
	ResultSet retResSet = null;
	try
	{

	    // String sSqlStmt = sqlp.getProperty("SelCoffeeAll","");
	    String sSqlStmt = queryAll;
	    logMsg("Query String :  " + sSqlStmt);

	    // invoking getResultSet method
	    logMsg("Calling getResultSet on Statement");
	    boolean retVal = stmt.execute(sSqlStmt);

	    retResSet = stmt.getResultSet();

	    if (retResSet instanceof ResultSet)
	    {
		logMsg("getResultSet method returns a ResultSet object ");
	    }
	    else
	    {
		logErr(" getResultSet method does not return a ResultSet object");
		throw new Exception("Call to getResultSet is Failed!");
	    }
	}
	catch (SQLException sqle)
	{
	    logErr("SQL Exception " + sqle.getMessage());
	    throw new Exception("Call to getResultSet is Failed!", sqle);
	}
	catch (Exception e)
	{
	    logErr("Unexpected exception " + e.getMessage());
	    throw new Exception("Call to getResultSet is Failed!", e);
	}
    }

    /* cleanup */
    @AfterClass
    public static void cleanup() throws Exception
    {
	try
	{
	    if (rs != null)
	    {
		rs.close();
	    }
	    // dbSch.destroyData(conn);
	    // Close the Statement object
	    stmt.close();
	    // close the Database
	    dbSch.dbUnConnect(conn);

	    logMsg("Cleanup ok;");
	}
	catch (Exception e)
	{
	    logErr("An error occurred while closing the database connection");
	}
    }

}
